﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Stone_Jumper
{
    public class MySize
    {
        public int Width { get; set; }
        public int Height { get; set; }
    }
    public enum JumperStateEnum
    {
        HasToBounce,
        HasToFallDown,
        Zero
    }

    public enum JumperLineEnum
    {
        Left,
        Right,
        Up
    }

    public class Jumper : MovabledObject

    {
        
        private readonly MySize _windowSize;
        private readonly MySize _barsSize;
        private event EventHandler GameOver;
        private MySize _jumperSize;

        public MySize JumperSize {
            get { return _jumperSize; }
            set { _jumperSize = value; }
        }
    
        private JumperLineEnum _jumperLine = JumperLineEnum.Up;
        private JumperStateEnum _jumperState = JumperStateEnum.HasToFallDown;

        public JumperLineEnum JumperLine
        {
            get { return _jumperLine; }
            set
            {
                _jumperLine = value;
            }
        }

        public JumperStateEnum JumperState
        {
            get { return _jumperState; }
            set { _jumperState = value; }
        }

    


    public Jumper(PointF position,MySize jumperSize,MySize barsSize,MySize windowSize,Game gameForm) : base(position)
        {
            GameOver += new EventHandler(gameForm.GameOver);
            this.JumperSize = jumperSize;
            _barsSize = barsSize;
            this._windowSize = windowSize;
        }
        public void CheckForBounce(List<PointF> barsList)
        {
            
            try
            {
                for (int i = 0; i < barsList.Count; i++)
                {
                    var tf = barsList[i];
                    if ((this.position.X + JumperSize.Width) > tf.X && (this.position.X < (tf.X + this._barsSize.Width)) &&
                        ((this.position.Y + this.JumperSize.Height) >= tf.Y) &&
                        ((this.position.Y + this.JumperSize.Height) <= (tf.Y + 10f)))
                    {


                        JumperState = JumperStateEnum.HasToBounce;

                    }
                }
            }
            catch (Exception exception)
            {
                throw new Exception();
            }
        }

        public void PlayerBounds()
        {

            
            if (position.X < (5 - JumperSize.Width))
            {
                position.X = _windowSize.Width - 5;

            }
            if (position.X > (_windowSize.Width - 5))
            {
                position.X = 5 - JumperSize.Width;

            }
            if (position.Y < -10)
            {
                JumperState = JumperStateEnum.HasToFallDown;
               
            }
            if ((position.Y +JumperSize.Width) > (_windowSize.Height + 10))
            {
                
                GameOver.Invoke(this,null);
                
              
            }
            switch (JumperLine)
            {
                case JumperLineEnum.Left:
                {
                    position.X -= 1f;

                }
                    break;
                case JumperLineEnum.Right:
                {
                    position.X +=1f;
                }
                    break;
            }
        }

        

    }

    
}
